package cn.smbms.service;

import cn.smbms.dao.UserMapper;
import cn.smbms.pojo.Bill;
import cn.smbms.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;


    @Override
    public Integer getUserCount(String userName, Integer userRole) {
        return userMapper.getUserCount(userName,userRole);
    }

    @Override
    public List<User> getUserList(String queryName,
                                  Integer queryUserRole,
                                  Integer PageNo,
                                  Integer pageSize) {
        Integer currentPageNo = (PageNo-1)*pageSize;
        return userMapper.getUserList(queryName,queryUserRole,currentPageNo,pageSize);
    }

    @Override
    public User login(String userCode, String userPassword) {
        User user = null;
        user = userMapper.getLoginUser(userCode);
        //匹配密码
        if(null != user){
            if(!user.getUserPassword().equals(userPassword))
                user = null;
        }
        return user;
    }

    @Override
    public boolean add(User user) {
        return userMapper.add(user)>0?true:false;
    }

    @Override
    public User getUserById(Integer id) {
        return userMapper.getUserById(id);
    }

    @Override
    public boolean modify(User user) {
        return userMapper.update(user)>0?true:false;
    }

    @Override
    public boolean delete(Integer id) {
        return userMapper.delete(id)>0?true:false;
    }

    @Override
    public User getUserCode(String userCode) {
        return userMapper.getUserCode(userCode);
    }

    @Override
    public boolean pwdUpdate(String pwd, Integer id) {
        return userMapper.pwdUpdate(pwd,id)>0?true:false;
    }


}
